﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace CommonLib{
	//Template
	//单例Monobehaviour
	public class ISingleton<T> : MonoBehaviour where T : MonoBehaviour
	{
		private static object m_syncObject = new object();
		public static T Instance {
			get
			{
				lock (m_syncObject)
				{
					if (m_Instance == null)
					{
						m_Instance = FindObjectOfType<T>();
						if (m_Instance == null) {
							GameObject go = new GameObject(typeof(T).ToString());
							m_Instance = go.AddComponent<T>();
							DontDestroyOnLoad(go);
						}
					}
					return m_Instance;
				}
			}
		}
		private static volatile T m_Instance;
	}
}